Skip to content

perf(build): split the frontend bundle per route and add web vitals attribution - #543

Merged
jplacht merged 1 commit into
mainfrom
perf/bundle-splitting
Oct 1, 2026
Merged

jplacht merged 1 commit into
mainfrom
perf/bundle-splitting

Conversation

@jplacht

@jplacht jplacht commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

What and why

Every first visit downloaded the whole app before anything rendered: the app-core manualChunks rule pulled all features and heavy libraries (chart.js, vue-flow, dagre, showdown, papaparse, yalps, lightweight-charts) into the initial load. Now the landing page and each route load only what they need, a deploy no longer leaves an open tab on a blank page, and PostHog web vitals name the offending element.

Changes

  • Drop the app-core rule; only vue, vue-router, pinia, vue-i18n and posthog keep named chunks. naive-ui splits by usage (one naive-ui chunk was measured and was slower: initial JS 259 → 336 KB brotli, FCP +6–15 %)
  • Remove the global VueShowdownPlugin; Help page and drawer set flavor="github" and table/emoji options locally
  • New src/lib/chunkReload.ts: when a deploy removed a lazy chunk, reload once onto the target route; within 30 s of that, show "This page couldn't load…" instead of looping. PostHog chunk failures (content blockers) never reload
  • PostHog init: capture_performance: { web_vitals_attribution: true }
  • lodash → lodash-es (5 imports), so the shell no longer ships all of lodash

Performance

Initial JS on / (entry + modulepreloads): 55 files, 764 KB → 5 files, 212 KB brotli (−72 %).

Lighthouse, median of 5 cold runs, main → branch (before the lodash-es change):

page FCP LCP TBT JS transferred
/ mobile 6488 → 3010 ms (−54 %) 9571 → 6831 ms (−29 %) 52 → 41 ms 783 → 287 KB (−63 %)
/ desktop 1343 → 685 ms (−49 %) 1889 → 1225 ms (−35 %) 0 → 0 783 → 287 KB
empire mobile −43 % −22 % −19 % −33 %
plan mobile −52 % −17 % +26 % −32 %
search mobile −41 % −28 % −60 % −36 %
roi-overview mobile −42 % −24 % −15 % −34 %
help mobile −50 % −47 % −56 % −58 %

Plan mobile TBT: TBT only counts after first paint, and FCP moved 3.4 s earlier, so work that ran before the paint now falls inside the window. Total main-thread work on the plan page is lower on the branch (≈1415 ms vs ≈1530 ms, interleaved runs).

How it was verified

QA: PASS after 3 rounds (full, then scoped retests). pnpm test && pnpm tsc && pnpm lint && pnpm knip pass. All checks ran on the production build in the Docker e2e stack:

  • Smoke run over every route, logged in and out, at 1440 and 375: no failed assets, no empty pages, redirects correct. The only console errors are on /exchanges/<uuid>, /hq-upgrade-calculator and /production-chain, identical on main (seed data lacks some exchange data)
  • Help markdown, empire charts, vue-flow, lightweight-charts, CSV export/import, consent → vendor_posthog + $pageview (none without consent)
  • Simulated deploy: one reload onto the clicked route; permanently missing chunk: one reload, then the error, no loop
  • $web_vitals carries attribution after consent
  • Debounced preference sync still sends PATCH /user/preferences/ after the lodash-es switch
  • UI audit (landing, help, plan, empire): no regressions versus baseline

Screenshots: none. No visual change is intended; the QA screenshots only show pages looking the same as before.

After release: compare PostHog p75 web vitals of this version with 0.31.0 once each has ~1,000 LCP samples.

🤖 Generated with Claude Code

…ttribution

- Drop the app-core manualChunks rule; only vue, vue-router, pinia, vue-i18n
  and posthog keep named chunks, naive-ui splits by usage (measured faster)
- Remove the global VueShowdownPlugin; Help page and drawer set options locally
- Reload once onto the target route when a deploy removed a lazy chunk;
  show an error instead of looping (30 s sessionStorage guard)
- PostHog: capture_performance.web_vitals_attribution
- lodash -> lodash-es so the shell no longer ships all of lodash
- Initial JS on / 764 KB -> 212 KB brotli; mobile FCP on / -54 %, LCP -29 %

Spec: specs/2026-10-01-bundle-splitting-vitals-attribution.md

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@netlify

netlify Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for prunplanner-preview ready!

Name Link
🔨 Latest commit 8014927
🔍 Latest deploy log https://app.netlify.com/projects/prunplanner-preview/deploys/6abe77b10507470008948fc6
😎 Deploy Preview https://deploy-preview-543--prunplanner-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codacy-production

codacy-production Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 19 complexity · 0 duplication

Metric Results
Complexity 19
Duplication 0

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.02% coverage variation

Metric Results
Coverage variation ✅ +0.02% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2943c2a) 3544 3455 97.49%
Head commit (8014927) 3571 (+27) 3482 (+27) 97.51% (+0.02%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#543) 27 27 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@jplacht
jplacht merged commit f0fabc1 into main Oct 1, 2026
11 checks passed
@jplacht
jplacht deleted the perf/bundle-splitting branch October 1, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant